package com.siloam.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.SqlSession;

import com.siloam.module.GroupUser;

public class GroupUserDao {
	
	private SqlSession sqlSession;

	public SqlSession getSqlSession() {
		return sqlSession;
	}

	public void setSqlSession(SqlSession sqlSession) {
		this.sqlSession = sqlSession;
	}

	private String getMapper(String method) {
		return "com.siloam.sqlmap.GroupUserMapper." + method;
	}
	
	public List<GroupUser> listGroupUsers(int groupId){
		return sqlSession.selectList(getMapper("listGroupUser"), groupId);
	}
	
	public void setMemberType(int id, int type){
		Map<String, Integer> params = new HashMap<String, Integer>();
		params.put("type", type);
		params.put("id", id);
		sqlSession.update(getMapper("setMemberType"), params);
	}
	
	public void add(int type, int userId, int groupId){
		Map<String, Integer> params = new HashMap<String, Integer>();
		params.put("type", type);
		params.put("userId", userId);
		params.put("groupId", groupId);
		sqlSession.insert(getMapper("add"), params);
	}
	
	public void delete(String ids){
		sqlSession.delete(getMapper("delete"), ids);
	}
	
}
